package com.mijie.homi.admin.web.channel;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.mijie.homi.admin.domain.commom.Channel;
import com.mijie.homi.admin.service.channel.ChannelService;
import com.mijie.homi.common.domain.mood.MoodInfo;
import com.mijie.homi.common.util.HomiUtil;

@Controller
@RequestMapping("/channel")
public class ChannelController {

	@Autowired
	private ChannelService service;
	
	@RequestMapping("/list")
	public String list(Model model){
		List<Channel> list = service.listChannel();
		model.addAttribute("list",list);
		return "channel/list";
	}
	
	@RequestMapping("/create")
	public String create(){
		return "channel/create";
	}
	
	@RequestMapping("/save")
	public String save(HttpServletRequest request,String name) throws Exception{
		service.createChannel(name);
		return "redirect:/channel/list.shtml";
	}
	
	@RequestMapping("/edit")
	public String edit(Model model,int id){
		Channel channel = service.getChannel(id);
		model.addAttribute("channel",channel);
		return "channel/edit";
	}
	
	
	@RequestMapping("/update")
	public String update(Channel channel) throws Exception{
		service.updateChannel(channel);
		return "redirect:/channel/list.shtml";
	}
}
